package com.longway.core.toolbox.wdp.api;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

public class DbAuthorizationInfoFactory implements AuthorizationInfoFactory{
	
	private static final DbAuthorizationInfoFactory me = new DbAuthorizationInfoFactory();
	
	public static DbAuthorizationInfoFactory me() {
		return me;
	}

	@Override
    public AuthorizationInfo getAuthorizationInfo(String appId) {
		Record record = Db.findFirst("select * from shop_authorization where authorizerAppid = ? ",appId);
		AuthorizationInfo authinfo = new AuthorizationInfo();
		authinfo.setAuthorizerAppid(record.getStr("authorizerAppid"));
		authinfo.setAuthorizerAccessToken(record.getStr("authorizerAccessToken"));
		authinfo.setExpiredTime(record.getLong("expiredTime"));
		authinfo.setAuthorizerRefreshToken(record.getStr("authorizerRefreshToken"));
		/*String function = record.getStr("funcInfo");
		JSONArray funcs = JsonKit.parse(function, JSONArray.class);*/
		return authinfo;
	}
     
}
